package com.big.spike.controller;

import com.big.common.result.Result;
import com.big.model.vo.lua.PatientLuaVo;
import com.big.spike.service.PatientService;
import com.big.spike.service.StockService;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;


@RestController
@RequestMapping("/api/spike")
@Slf4j
public class SpikeController {


    @Autowired
    StockService stockService;

    @Autowired
    PatientService patientService;




    @ApiModelProperty(value = "改变库存")
    @GetMapping("/stock/{mId}")
    public Result stock(@PathVariable String mId){
        boolean b = stockService.changeStock(mId);
        return Result.ok(b);
    }


    @ApiModelProperty(value = "用户秒杀记录查看")
    @GetMapping("/recording/info/{pId}/{mId}")
    public boolean recording(@PathVariable String pId,@PathVariable String mId){
        boolean b = patientService.recording(pId,mId,"info");
        return b;
    }

    @ApiModelProperty(value = "添加用户秒杀记录")
    @PostMapping("/recording/save")
    public Result  saveRecording(PatientLuaVo patientLuaVo){
        boolean b = patientService.saveRecording(patientLuaVo);
        return  Result.ok(b);
    }


    @ApiModelProperty(value = "添加用户秒杀记录")
    @PostMapping("/assemble")
    public void    assemble(PatientLuaVo patientLuaVo){

        for (int i = 0; i <4; i++) {
//            patientLuaVo.setPId(String.valueOf(i));
            String b = patientService.assemble(patientLuaVo);
            log.info("测试值:{}",b);
        }
    }


}
